<?php
class Application extends AppModel {
	var $name = 'Application';
	
	//ACL this is a crontrolled object ACO
	var $actsAs = array('Acl' => array('type' => 'controlled'));
	
	function parentNode() {
		return null;
	}
	
/**
* START ASSOCIATION INFORMATION
******************************************************************************
*/

	var $belongsTo = array(
		'User' => array(
			'className' => 'User',
			'foreignKey' => 'user_id'
		)
	);
	
	var $hasOne = array(
		'Studyinterest' => array(
			'className' => 'Studyinterest',
			'foreignKey' => 'application_id'
		),
		'Score' => array(
			'className' => 'Score',
			'foreignKey' => 'application_id'
		),
		'Courselist' => array(
			'className' => 'Courselist',
			'foreignKey' => 'application_id'
		)
	);
	
	var $hasMany = array(
		'School'=> array(
			'className' => 'School',
			'foreignKey' => 'application_id',
		),
		'Reference' => array(
			'className' => 'Reference',
			'foreignKey' => 'application_id',
			'fields' => array(
				'id', 
				'uid',
				'created', 
				'modified',
				'application_id',
				'file_name',
				'file_size',
				'lastname',
				'firstname',
				'title',
				'phone',
				'email',
				'ferpa_waived',
				'use_web',
				'knowledge_length',
				'has_grad_prog', 
  			'would_admit', 
  			'not_admit_info',
  			'intel_ability',
				'academic_prep',
				'maturity',
				'interpersonal_skills',
				'oral_comm',
				'written_comm', 
				'finishes_tasks',
				'creative_think',
				'independent_work',
				'professional_clinic', 
				'motivation', 
				'originality',
				'initiative',
				'critical_thinking',
				'emot_stability', 
				'perseverance',
				'overall',
				'complete'
			)
		),
		'Attachment' => array(
			'className' => 'Attachment',
			'foreignKey' => 'application_id',
			'fields' => array(
				'id', 
				'created', 
				'modified',
				'application_id',
				'doc_type',
				'mime_type',
				'file_name',
				'file_size'
			)									
		)
	); //end hasMany array.
	
	/************************************************************
 	*********************** MODEL FUNCTIONS *********************
 	************************************************************/
 	
 	function change_status ($id=null, $field= null, $new_status= null, $message = null) {
 		if ($id && $field) {
 			switch ($new_status) {
 				case 0: 
 					$new_status= 'red';
 					break;
 				case 1:
 					$new_status= 'yellow';
 					break;
 				case 2:
 					$new_status= 'green';
 			}
 		
 			$this->id = $id;
 			$this->saveField($field . '_stat', $new_status);
 			if ($message !== null) {
 				$this->saveField($field . '_msg', $message);
 			}
 			$this->saveField($field . '_mod', date('Y-m-d H:i:s'));
 		}
 	}
 	
 	function get_status ($id= null, $field= null ) {
 		if ($id && $field) {
 			$this->id = $id;
 			return $this->field($field);
 		}
 		return null;
 	}
}
